package com.weixinli.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.junit.runner.RunWith;
import org.springframework.stereotype.Repository;

import com.weixinli.beans.UserComment;
import com.weixinli.dao.IUserCommentDao;

@Repository("iUserCommentDao")
public class UserCommentDaoImpl implements IUserCommentDao{
	@Resource(name="sqlSession")
	private SqlSession sqlSession;

	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}

	public int addUserComment(UserComment uc) {
		return sqlSession.insert("userCommentDao.addComment", uc);
		//return uc.getCid();
	}
	
	public UserComment newOne(int cid) {
		Map< String,Object> map=new HashMap<String, Object>();
		map.put("cid", cid);
		return sqlSession.selectOne("userCommentDao.newOne",map);
	}

	public int delUserComment(Integer cid) {
		return 0;
	}

	public List<UserComment> getAllComment(Integer area_id) {
		return null;
	}

	public int getTotalComment(Integer objid, Integer area_id) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("objid", objid);
		map.put("area_id", area_id);
		return sqlSession.selectOne("userCommentDao.findCommentTotal", map);
	}

	public int getCommentNum(Integer objid, Integer area_id) {
		return 0;
	}

	public List<UserComment> getPageComment(Integer pageNo, Integer pageSize, Integer objid, Integer area_id) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("min", (pageNo-1)*pageSize);
		map.put("max", pageSize);
		map.put("objid", objid);
		map.put("area_id", area_id);
		return sqlSession.selectList("userCommentDao.findCommentById", map);
	}
	
	public List<UserComment> FMgetAllComment(Integer area_id, Integer objid) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("area_id", area_id);
		map.put("objid", objid);
		return sqlSession.selectList("userCommentDao.oneIdAllComment", map);
	}

	public int addUserNote(UserComment uc) {
		System.out.println(uc+"uc           uc========");
		return sqlSession.insert("userCommentDao.addUserNote",uc);
	}
	
	public List<UserComment> AllNote(int min,int max) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("min", min);
		map.put("max", max);
		map.put("area_id", 6);
		return sqlSession.selectList("userCommentDao.allNote",map);
	}

	public int getTotalUserComment(Integer w_uid) {
		return 0;
	}

	public int FMaddUserComment(Integer id, Integer objid, Integer area_id, String content, String time) {
		return 0;
	}

	public List<UserComment> FMgetComment(Integer area_id, Integer w_id, Integer objid) {
		return null;
	}

	public List<UserComment> getOneObjComment(Integer objid, Integer area_id) {
		UserComment c = new UserComment();
		c.setArea_id(area_id);
		c.setObjid(objid);
		return sqlSession.selectList("userCommentDao.getOneObjComment", c);
	}

}
